<template>
  <div class="evaluate-detail">
    <el-page-header @back="$router.push('/evaluate/manage')" content="审计管理详情"> </el-page-header>
    <div class="sec-detail-main">
      <!-- 基本信息 -->
      <secDescriptions
        :data="contentData"
        :extra="true"
        :optionData="optionData"
        :loadingProp="loadingProp"
        :colon="true"
        :labelStyle="{ width: '100px', 'text-align': 'right', 'line-height': '36px' }"
        :contentStyle="{ 'line-height': '36px' }"
        :column="3"
        :border="false"
        :keyData="baseKey"
        title="资产信息"
      >
        <template slot="extra" v-if="progressData.admin === '1' || progressData.user === '1'">
          <el-tooltip effect="dark" content="保存基本信息" placement="top">
            <el-button type="primary" @click="saveBaseInfo" circle><i class="iconfont icon-baocun"></i></el-button>
          </el-tooltip>
        </template>
        <template v-slot:gitList>
          <el-tag v-for="(item, index) in contentData.gitList" style="margin: 0 5px 5px 0" :key="index">{{
            item
          }}</el-tag>
        </template>
        <template v-slot:odinList>
          <el-tag v-for="(item, index) in contentData.odinList" style="margin: 0 5px 5px 0" :key="index">{{
            item
          }}</el-tag>
        </template>
      </secDescriptions>
      <!-- 资产标签 -->
      <div class="cls title">资产标签</div>
      <sec-tags :data="tagList" @refresh="initPage"></sec-tags>
      <!-- 审计进度 -->
      <div class="cls title">审计进度</div>
      <el-steps :active="active" finish-status="success">
        <el-step v-for="(item, index) in steps" :key="index" :title="item.statusName">
          <template slot="description">
            <div>
              <span v-if="item.operaUser">操作人:{{ item.operaUser }}</span
              ><br />
              <span v-if="item.time">操作时间：:{{ item.time }}</span>
            </div>
          </template>
        </el-step>
      </el-steps>
      <!-- 审计项设定 -->
      <div style="margin-top: 20px">
        <div class="cls title">审计项设定</div>
        <div class="evaluate-setting" style="margin-bottom: 20px">
          <div class="btn-box">
            <el-tooltip
              effect="dark"
              content="添加HIVE表"
              placement="top"
              v-if="progressData.admin === '1' || progressData.user === '1'"
            >
              <el-button plain type="primary" icon="el-icon-plus" @click="addHiveTable" circle></el-button>
            </el-tooltip>
            <el-tooltip
              effect="dark"
              content="保存"
              placement="top"
              v-if="progressData.admin === '1' || progressData.user === '1'"
            >
              <el-button plain type="primary" @click="saveHiveTable" circle
                ><i style="font-size: 12px" class="iconfont icon-baocun"></i
              ></el-button>
            </el-tooltip>
            <el-tooltip v-if="showQuestion" effect="dark" content="调查问卷" placement="top">
              <el-button plain type="primary" @click="questionnaireClick" icon="el-icon-link" circle></el-button>
            </el-tooltip>
          </div>
          <el-collapse v-model="dbTableDetailVal">
            <el-collapse-item title="库表详情" name="1">
              <eTable :tableData="evalSettingTable.rows" :tableCol="evalSettingTable.cols"></eTable>
            </el-collapse-item>
          </el-collapse>
        </div>
      </div>
      <!-- 审计结果 -->
      <!-- <el-divider></el-divider> -->
      <el-tabs v-model="tabName">
        <el-tab-pane label="审计结果" name="审计结果">
          <eTable
            :cellClassName="cellClassName"
            :loading="evalResult.loading"
            :optionData="evalResult.optionData"
            :tableData="evalResult.rows"
            :colType="evalResult.colType"
            :disabledProp="evalResult.disabledProp"
            :tableCol="evalResult.cols"
          >
            <template v-slot:relScene="{ data }">
              <span v-if="!(data.row.relScene && data.row.relScene.length > 0)">
                <el-tag :type="data.row.status == '-1' ? 'info' : ''">通用场景</el-tag>
              </span>
              <span v-else>
                <el-tag
                  v-for="(item, index) in data.row.relScene"
                  :type="data.row.status == '-1' ? 'info' : ''"
                  :key="index"
                  style="margin: 4px"
                >
                  {{ item }}
                </el-tag>
              </span>
            </template>
            <template v-slot:upload="{ data }">
              <uploadImg :row="data.row" @uploadSuccess="save(true)"></uploadImg>
            </template>
          </eTable>
        </el-tab-pane>
        <el-tab-pane label="风险列表" name="风险列表" :disabled="!tabDisabled.includes(progressData.status)">
          <eTable :tableData="riskTable.rows" :tableCol="riskTable.cols"></eTable>
          <div
            style="text-align: center; margin-top: 15px"
            v-if="progressData.recification !== '2' && progressData.admin === '1' && progressData.status === '24'"
          >
            <el-button type="primary" @click="setRiskSoc">同步漏洞平台并生成报告</el-button>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div
        class="submit-box"
        style="text-align: center; margin: 20px 0"
        v-if="
          progressData.status !== '36' &&
          progressData.status !== '37' &&
          progressData.status !== '50' &&
          progressData.admin === '1'
        "
      >
        <el-button type="primary" @click="rollback" v-if="progressData.status == 13 && auditType === 'all'"
          >回 退</el-button
        >
        <el-button type="primary" @click="save" v-if="!saveBtnShowStatus.includes(progressData.status)"
          >保 存</el-button
        >
        <el-button
          type="primary"
          @click="saveAndSubmit"
          v-if="progressData.status === '11' && progressData.taskStatus === '30'"
          >信息补充</el-button
        >
        <el-button
          type="primary"
          v-if="subBtnShowStatus.includes(progressData.status) && progressData.taskStatus === '30'"
          @click="saveAndSubmit"
        >
          提交结果
        </el-button>
        <el-button
          type="primary"
          v-if="accomplishBtnShowStatus.includes(progressData.status) && progressData.recification == '2'"
          @click="saveAndSubmit"
          >完成审计</el-button
        >
      </div>
    </div>
    <el-dialog title="URL列表" :visible.sync="urlDiaShow" width="80%">
      <eTable :tableData="urlTable.rows" :tableCol="urlTable.cols"></eTable>
    </el-dialog>
    <el-dialog title="关联场景" :visible.sync="sceneDiaShow" width="60%">
      <eTable :tableData="sceneTable.rows" :tableCol="sceneTable.cols"></eTable>
    </el-dialog>
    <el-dialog title="人工忽略" :visible.sync="errDiaShow" width="50%">
      <myForm ref="errReport" :rules="rules" :ruleForm="ruleForm" :formData="formData"></myForm>
    </el-dialog>
    <!-- 审计结果详情 -->
    <el-dialog title="详情" :visible.sync="detailShow" width="50%">
      <myForm :ruleForm="detailForm" :formData="detailFormData"></myForm>
    </el-dialog>
    <!-- 信息补充阶段 -->
    <el-dialog title="信息补充" :visible.sync="infoDiaShow" :modal="true" append-to-body width="50%">
      <el-result icon="warning" title="请注意" subTitle="请先补充审计需要的系统信息">
        <template slot="extra">
          <el-button type="primary" @click="questionnaireClick">信息补充</el-button>
        </template>
      </el-result>
    </el-dialog>
  </div>
</template>

<script>
import { config } from "@/textConfig";
import secDescriptions from "components/descriptions/myDescriptions";

import eTable from "components/table/comTable";
import myForm from "components/formValidate/myForm";
import secTags from "components/secTags.vue";
import { addWhiteMixin } from "common/js/mixin";
import uploadImg from "./components/uploadImg.vue";
import {
  reportDetailApi,
  assetsDetailApi,
  reportHiveinfoApi,
  reportItemsApi,
  savehiveApi,
  userApi,
  riskUrlsApi,
  saveOrSubmitApi,
  autoScanItemApi,
  itemManualApi,
  saveBackStatusApi,
} from "api/evaluateApi";
import { assetsSave } from "api/propertyManage";
import { riskListApi, riskSocApi, riskMisreportApi, riskHoleStatusApi, riskLevelSaveApi } from "api/controlApi";
import Cookies from "js-cookie";
export default {
  name: "evaluateDetail",
  mixins: [addWhiteMixin],
  props: {},
  components: {
    secDescriptions,
    eTable,
    secTags,
    myForm,
    uploadImg,
  },
  data() {
    return {
      auditType: "all",
      showQuestion: true, //是否展示问卷调查 全自动审计不需要填写
      dbTableDetailVal: [], //审计项设定 库表详情折叠面板val
      tagList: [], //资产标签
      infoDiaShow: false, //信息补充阶段展示弹框
      selectIndexRow: {}, //点击url列表时存储的行的数据
      detailShow: false,
      detailForm: {
        json: "",
      },
      detailFormData: [{ prop: "json", label: "", type: "textarea", rows: 20, disabled: true }],
      codeSessionRole: [], //权限控制
      // evalResultColDisStatus: ["10", "11", "12"], //审计结果tab界面 审计结果列在审计进度10（发起审计），11（系统审计），12（信息补充）置灰
      evalResultColDisStatus: ["13"], //审计结果tab界面 审计结果之后再审计确认（状态码是13）可操作，其他状态都是置灰
      saveBtnShowStatus: ["24", "25"], //保存按钮展示的审计进度状态码(!非的状态)
      //infoBtnShowStatus: ["11", "30"], //信息补充按钮展示的审计进度状态码（11是进度码，30是任务状态码）
      subBtnShowStatus: ["10", "12", "13"], //提交结果按钮展示的审计进度状态码
      accomplishBtnShowStatus: ["24", "25"], //完成审计按钮展示的审计进度状态码
      selectRisk: {},
      importSystems: ["manual", "major", "sensitive", "general"],
      tabName: "审计结果",
      active: 1,
      query: {},
      progressData: {}, //审计进度数据
      urlDiaShow: false, //url列表弹框
      errDiaShow: false, //误报弹框
      // holeDiaShow: false, //同步漏洞平台弹框
      sceneDiaShow: false, //关联场景弹框
      tabDisabled: ["24", "25", "36", "37", "50"], //风险列表展示
      contentData: {}, //基本信息数据
      optionData: {
        //基础信息下拉框数据
        noticeUsersVal: [],
        pmUsersVal: [],
      },
      steps: [{ statusName: "", time: "", operaUser: "" }],
      loadingProp: { noticeUsersVal: false, pmUsersVal: false },

      //审计项设定
      evalSettingTable: {
        cols: [
          { label: "库名", placeholder: "请输入库名（hive）", prop: "dbName", type: "text" },
          {
            label: "表名",
            prop: "tableName",
            type: "text",
            placeholder: "请输入hive表名（多个表之间用 , 隔开）",
          },
          {
            label: "操作",
            prop: "operation",
            width: 100,
            // disabledIndex: [0], //失效的下标
            children: [
              {
                label: "删除",
                click: ({ row, column, $index }) => {
                  this.evalSettingTable.rows.splice($index, 1);
                },
              },
            ],
          },
        ],
        rows: [{ tableName: "", dbName: "" }],
      },
      //审计结果数据
      evalResult: {
        //列的类型
        loading: false,
        disabledProp: {
          status: true,
        },
        colType: {
          riskLevel: "select",
          pocRiskLevel: "select",
          remark: "textarea",
          status: "select",
        },
        optionData: {
          pocRiskLevel: this.$store.state.dictionary.level,
          status: this.$store.state.dictionary.status,
        },
        cols: [
          { label: "指标名称", prop: "name", align: "left" },
          { label: "指标要求", prop: "reportItemContent", align: "left", width: 300 },
          {
            label: "关联场景",
            prop: "relScene",
            type: "slot",
            align: "left",
          },
          {
            label: "现状描述",
            maxlength: 500,
            prop: "remark",
            maxlength: 500,
            width: 300,
            blur: () => {
              this.getAdminAuth() && this.save();
            },
          },
          {
            type: "slot",
            label: "材料上传",
            prop: "upload",
            width: 300,
          },
          {
            label: "审计结果",
            prop: "status",
            width: 200,
            change: () => {
              this.getAdminAuth() && this.save(true);
            },
            formatter: (row, column, cellValue, index) => {
              if (!this.getAdminAuth()) {
                return this.utils.getDicLabel("status", cellValue);
              }
            },
          },
          {
            label: "操作",
            prop: "operation",
            width: 150,
            fixed: "right",
            children: [
              {
                label: "URL列表",
                hide: ({ row }) => {
                  return row.auto != 1 || row.reportItem === "md_001_classific";
                },
                click: ({ row, column, $index }) => {
                  this.selectIndexRow = row;
                  this.getRiskUrls();
                },
              },
              {
                label: "刷新",
                hide: ({ row }) => {
                  let arr = ["13", "24", "25"]; //这些状态展示刷新按钮
                  return row.auto != 1 || !arr.includes(this.progressData.status); //自动化展示
                },
                click: ({ row, column, $index }) => {
                  this.utils.$confirm({ content: "确认触发刷新操作？" }, () => {
                    autoScanItemApi({ itemId: row.id, sourceType: "datasec_report" }).then((res) => {
                      this.message.state(res);
                      this.getReportDetail();
                    });
                  });
                },
              },
              {
                label: "详情",
                hide: ({ row }) => {
                  return row.manual == 0 || row.auto != 1; //人工辅助并且自动化显示详情
                },
                click: ({ row, column, $index }) => {
                  this.detailShow = true;
                  itemManualApi({ dateType: "datasec_report", itemId: row.id }).then((res) => {
                    if (!res.data) {
                      this.detailForm.json = "";
                      return;
                    }
                    let value = JSON.parse(res.data);
                    this.detailForm.json = JSON.stringify(value, null, 4); //为了展示的更美观
                  });
                },
              },
            ],
          },
        ],
        rows: [],
      },
      //url列表
      urlTable: {
        cols: [
          { label: "URL", prop: "url" },
          { label: "说明", prop: "remark" },
          { label: "负责人", prop: "urlLeader" },
          { label: "发生时间", prop: "createTime" },
          {
            label: "url状态",
            prop: "auth",
            formatter: (row, column, cellValue, index) => {
              return this.utils.getDicLabel("auth", cellValue);
            },
          },
          { label: "备注", prop: "remark" },
          {
            label: "操作",
            prop: "operation",
            width: 100,
            children: [
              {
                labelFunc: ({ row, column, $index }) => {
                  //加白和不加白的显示 通过策略类型判断 如果是url策略展示 系统策略就不展示
                  if (row.strategyType == 1 && row.white == 1) {
                    return "取消加白";
                  } else if (row.strategyType == 1) {
                    return "加白";
                  } else {
                    return "-";
                  }
                },
                click: ({ row, column, $index }) => {
                  this.selectUrlRow = row;
                  if (row.strategyType == 1 && row.white == 1) {
                    this.addWhiteHandler();
                  } else if (row.strategyType == 1) {
                    this.addWhiteHandler("add");
                  }
                },
              },
            ],
          },
        ],
        rows: [],
      },
      sceneTable: {
        cols: [{ label: "场景名称", prop: "name" }],
        rows: [],
      },
      //风险列表
      riskTable: {
        cols: [
          // { label: "风险ID", prop: "id", width: 80 },
          { label: "风险名称", prop: "riskName", width: 250, align: "left" },
          { label: "风险描述", prop: "holeDetail", width: 300, align: "left" },
          { label: "修复建议", prop: "repairRecommend", width: 300, align: "left" },

          {
            width: 150,
            label: "风险等级",
            prop: "level",
            change: ($event, { row }) => {
              riskLevelSaveApi({ id: row.id, level: row.level }).then((res) => {
                this.message.state(res);
              });
            },
            optionData: this.$store.state.dictionary.level,
            type: "select",
            // formatter: (row, column, cellValue, index) => {
            //   return this.utils.getDicLabel("level", cellValue);
            // },
          },
          { label: "关联指标", prop: "itemName" },
          // { label: "风险类型", prop: "holeType", width: 150 },
          {
            label: "风险状态",
            prop: "status",
            width: 100,
            formatter: (row, column, cellValue, index) => {
              return this.utils.getDicLabel("100700", cellValue);
            },
          },
          { label: "创建时间", prop: "createTimeText", width: 150 },
          {
            label: "操作",
            prop: "operation",
            width: 220,
            children: [
              {
                label: "同步漏洞平台",
                hide: ({ row, column, $index }) => {
                  if (this.$common.isPerIgnore(row.status)) {
                    return true;
                  }
                  let arr = ["0"]; //风险状态码
                  return !arr.includes(row.status);
                },
                click: ({ row, column, $index }) => {
                  // this.holeDiaShow = true;
                  this.utils.$confirm({ content: "是否确认同步漏洞平台?" }, () => {
                    this.selectRisk = row;
                    this.asyncHoleConfirm();
                  });
                },
              },
              {
                label: "人工忽略",
                hide: ({ row, column, $index }) => {
                  let arr = ["0"];
                  return !arr.includes(row.status);
                },
                click: ({ row, column, $index }) => {
                  this.errDiaShow = true;
                  this.ruleForm.remark = "";
                  this.selectRisk = row;
                },
              },
              {
                label: "详情",
                click: ({ row, column, $index }) => {
                  this.$router.push({
                    path: "/control/risk/detail",
                    query: { riskId: row.id, assetId: row.assetId, code: row.code, assetType: row.assetType },
                  });
                },
              },
              {
                hide: ({ row, column, $index }) => {
                  if (this.$common.isPerIgnore(row.status)) {
                    return true;
                  }
                  let arr = ["1-4", "5"];
                  return !arr.includes(row.status);
                },
                label: "同步工单状态",
                click: ({ row, column, $index }) => {
                  riskHoleStatusApi({ riskId: row.id, anquanId: row.anquanId }).then((res) => {
                    this.message.success({ message: res.msg });
                    this.getRiskList();
                  });
                },
              },
              {
                hide: ({ row, column, $index }) => {
                  if (this.$common.isPerIgnore(row.status)) {
                    return true;
                  }
                  let arr = ["0", "12"];
                  return arr.includes(row.status);
                },
                label: "工单详情",
                click: ({ row, column, $index }) => {
                  let domain = "http://anquan.didichuxing.com"; //测试的地址是http://anquan-test.didichuxing.com
                  window.open(`${domain}/project/portals/pages/hole-detail.html?id=${row.anquanId}`);
                },
              },
            ],
          },
        ],
        rows: [],
      },
      ruleForm: {
        remark: "",
      },
      rules: {
        remark: [{ required: true, message: config.input, trigger: "blur" }],
      },
      formData: [
        { type: "textarea", label: "备注", prop: "remark" },
        {
          type: "operation",
          style: { "text-align": "right" },
          children: [
            {
              label: "取 消",
              click: () => {
                this.errDiaShow = false;
              },
            },
            {
              label: "确 认",
              type: "primary",

              click: () => {
                if (this.$refs.errReport.submitForm()) {
                  this.errReportConfirm();
                }
              },
            },
          ],
        },
      ],
    };
  },
  computed: {},
  created() {
    this.baseKey = [
      //基本信息
      { label: "资产来源", prop: "source" },
      { label: "资产ID", prop: "id" },
      { label: "域名", prop: "domain" },
      { label: "系统名称", prop: "domainName" },
      {
        label: "资产级别",
        prop: "importSystem",
        formatter: (data) => {
          return this.utils.getDicLabel(100400, data.importSystem);
        },
      },
      {
        label: "资产类型",
        prop: "scanDev",
        formatter: (data) => {
          return this.utils.getDicLabel("scanDev", data.scanDev);
        },
      },
      {
        label: "资产状态",
        prop: "status",
        formatter: (data) => {
          return this.utils.getDicLabel("100500", data.status);
        },
      },
      { label: "访问性", prop: "netDev", span: 2 },
      //权属信息
      { label: "权属负责人", prop: "leaderName" },
      { label: "BP", prop: "bp" },
      {
        label: "PM",
        prop: "pmUsersVal",
        type: "select",
        filterable: true,
        multiple: true,
        remote: true,
        optionProps: { label: "name", value: "account" },
        remoteMethod: (query) => {
          this.loadingProp.pmUsersVal = true;
          userApi({ account: query }).then((res) => {
            this.loadingProp.pmUsersVal = false;
            this.optionData.pmUsersVal = res.data;
          });
        },
      },
      {
        label: "项目关注人",
        prop: "noticeUsersVal",
        type: "select",
        multiple: true,
        filterable: true,
        remote: true,
        optionProps: { label: "name", value: "account" },
        remoteMethod: (query) => {
          this.loadingProp.noticeUsersVal = true;
          userApi({ account: query }).then((res) => {
            this.loadingProp.noticeUsersVal = false;
            this.optionData.noticeUsersVal = res.data;
          });
        },
      },
      { label: "创建人", prop: "creator", span: 2 },
      { type: "slot", label: "git地址", prop: "gitList", span: 3 },
      { type: "slot", label: "odin地址", prop: "odinList", span: 3 },
      { label: "权属部门", prop: "dept2", span: 2 },
      //其他信息
      { label: "集群环境", prop: "cluster" },
      { label: "国家码", prop: "ctCode" },
      { label: "录入时间", prop: "createTimeText", span: 2 },
      { label: "系统简介", prop: "extraData", type: "textarea", span: 3, contentStyle: "width:50%" },
      // { label: "发起时间", prop: "createTimeText" },
      { label: "备注", prop: "remark1", type: "textarea", contentStyle: "width:50%" },
    ];
  },
  mounted() {
    this.auditTypeByPath = {
      "/evaluate/manage/detail": "all",
      "/evaluate/manage/auto/detail": "auto",
      "/evaluate/manage/quick/detail": "all_quick",
    };
    this.auditType = this.auditTypeByPath[this.$route.path];
    this.showQuestion = this.auditType === "all" ? true : false;
    this.query = this.$route.query;
    this.initPage(); //初始化界面
  },
  methods: {
    async initPage() {
      let reportData = await reportDetailApi({ id: this.query.id, assetId: this.query.assetId });
      //为了安全考虑，不能直接在url上修改报告id和资产id（资产id和报告id一定是关联的才可以）
      if (reportData.data) {
        this.tagList = reportData.data.tagList;
        this.setReportDetail(reportData.data); //审计进度数据
        this.getAssetsDetail(); //基本信息数据获取

        this.getReportHiveinfo(); //审计项设定
        this.getReportItems(); //审计结果
        this.getRiskList(); //风险列表
      }
    },
    //url列表数据
    getRiskUrls() {
      riskUrlsApi({ dateType: "datasec_report", itemId: this.selectIndexRow.id }).then((res) => {
        if (!res.data) {
          this.message.warning({ message: "url列表数据为空" });
          return;
        }
        if (res.data && Array.isArray(res.data)) {
          this.urlDiaShow = true;
          this.urlTable.rows = res.data;
          let paramType = res.data[0].paramType || "URL";
          this.urlTable.cols[0].label = paramType;
        }
      });
    },
    /**
     * @函数功能:获取风险列表数据
     * @参数输入:
     * @函数返回:
     */
    getRiskList() {
      riskListApi({ assetId: this.query.assetId, relationId: this.query.id, dateType: ["datasec_report"] }).then(
        (res) => {
          res.data.forEach((item) => {
            if (item.status != "0") {
              item.disabled = true;
            }
          });
          this.riskTable.rows = res.data;
        },
      );
    },
    /**
     * @函数功能:基本信息
     * @参数输入:
     * @函数返回:
     */
    getAssetsDetail() {
      assetsDetailApi({ id: this.query.assetId }).then((res) => {
        this.contentData = res.data;
        for (let key in this.contentData) {
          if (key === "noticeUsers") {
            let noticeUsers = this.contentData[key];
            this.optionData.noticeUsersVal = noticeUsers;
            this.$set(this.contentData, "noticeUsersVal", []); //重新添加一个noticeUsersVal 字段 存储选中的noticeUsers的值
            noticeUsers.forEach((item) => {
              this.contentData["noticeUsersVal"].push(item.account);
            });
          } else if (key === "pmUsers") {
            let pmUsers = this.contentData[key];
            this.optionData.pmUsersVal = pmUsers;
            this.$set(this.contentData, "pmUsersVal", []); //重新添加一个pmUsersVal 字段
            pmUsers.forEach((item) => {
              this.contentData["pmUsersVal"].push(item.account);
            });
          } else if (key === "importSystem") {
            if (this.contentData[key]) {
              this.contentData[key] = this.contentData[key].split(",");
              if (!this.importSystems.includes(this.contentData[key])) {
                this.contentData[key] = "";
              }
            } else {
              this.contentData[key] = "";
            }
          } else if (key === "netDev") {
            this.contentData[key] = this.utils.getDicLabel("100200", this.contentData[key]);
          }
        }
      });
    },
    /**
     * @函数功能:保存基本信息
     * @参数输入:
     * @函数返回:
     */
    saveBaseInfo() {
      let loading = this.openLoading();
      assetsSave({
        id: this.query.assetId,
        domain: this.contentData.domain,
        // importSystem: this.contentData.importSystem.join(","),
        pmUsers: this.contentData.pmUsersVal.join(","),
        noticeUsers: this.contentData.noticeUsersVal.join(","),
        extraData: this.contentData.extraData,
        remark1: this.contentData.remark1,
        gitList: this.contentData.gitList,
        hiveList: this.contentData.hiveList,
        odinList: this.contentData.odinList,
      }).then((res) => {
        loading.close();
        this.message.success({ message: res.msg });
      });
    },
    //@函数功能:审计进度接口数据获取
    getReportDetail() {
      reportDetailApi({ id: this.query.id, assetId: this.query.assetId }).then((res) => {
        this.setReportDetail(res.data);
      });
    },
    /**
     * @函数功能:审计进度数据格处理
     * 评估状态(status): 10创建 | 11系统评估 | 12信息补充 | 13评估确认 24漏洞整改 | 25漏洞复核 | 36 已完成 | 47 已归档 | 48 已删除
     */
    setReportDetail(data) {
      this.progressData = data;
      this.evalResult.disabledProp.status = !this.evalResultColDisStatus.includes(this.progressData.status);
      //tab切换默认选中的tab页
      this.tabName = this.tabDisabled.includes(this.progressData.status) ? "风险列表" : "审计结果";
      this.setStep();
      //审计结果 现状描述和审计结果能否操作
      if (this.progressData.admin != "1") {
        this.evalResult.colType.remark = "";
        this.evalResult.colType.status = "";
      }
      //是否显示信息补充弹框
      if (this.progressData.userAnswer == 0 && this.progressData.status == 12) {
        this.$nextTick(() => {
          this.infoDiaShow = true;
        });
      }
    },
    //审计进度admin是1表示审计有权限  user:1 说明是报告有权限
    getAdminAuth() {
      return this.progressData.admin === "1" ? true : false;
    },
    setStep() {
      let { reportOprDetails } = this.progressData;
      console.log("this.progressData", this.progressData);
      this.steps = [];
      //根据后台返回的数据，填充时间和操作人
      let newStatus = JSON.parse(JSON.stringify(this.$store.state.dictionary[100800]));
      ["auto", "all-quick"].includes(this.auditType) && newStatus.splice(2, 1);
      console.log("[ newStatus ] >", newStatus);
      newStatus.forEach((item, index) => {
        if (item.value) {
          let obj = { statusName: item.label, status: item.value, time: "", operaUser: "" };
          reportOprDetails.forEach((step) => {
            if (step.status == item.value) {
              obj.time = step.time;
              obj.operaUser = step.operaUser;
            }
          });
          this.steps.push(obj);
        }
        //走到了哪一步
        if (this.progressData.status == item.value) {
          this.active = this.progressData.status === "36" ? index + 1 : index;
        } else if (this.progressData.status === "37") {
          //已归档 审计进度到已完成步骤
          this.active = 6;
        } else if (this.progressData.status === "50") {
          //已归档 审计进度到已完成步骤
          this.active = -1;
        }
      });
      this.isShowAuditStandard(); //审计结果tab界面 审计标准列是否展示
    },
    isShowAuditStandard() {
      let isHave = this.evalResult.cols.some((item) => item.prop === "auditStandard");
      //审计确定 展示审计标准列
      if (this.progressData.status == "13") {
        !isHave &&
          this.evalResult.cols.splice(2, 0, { label: "审计标准", prop: "auditStandard", align: "left", width: 200 });
      } else {
        if (!isHave) {
          this.evalResult.cols = this.evalResult.cols.filter((item) => item.prop !== "auditStandard");
        }
      }
    },
    /**
     * @函数功能:审计项设定
     * @参数输入:
     * @函数返回:
     */
    getReportHiveinfo() {
      reportHiveinfoApi({ assetId: this.query.assetId }).then((res) => {
        this.evalSettingTable.rows = res.data;
      });
    },
    rollback() {
      let loading = this.openLoading();
      saveBackStatusApi({ id: this.query.id }).then((res) => {
        loading.close();
        let state = this.message.state(res);
        if (!state) return;
        this.initPage(); //初始化界面
      });
    },
    /**
     * @函数功能:审计结果
     * @参数输入:
     * @函数返回:
     */
    getReportItems() {
      this.evalResult.loading = true;
      reportItemsApi({ reportId: this.query.id, assetId: this.query.assetId }).then((res) => {
        this.evalResult.loading = false;
        res.data.forEach((item) => {
          if (item.status == "-1") {
            item.disabled = true;
          } else {
            item.disabled = false;
          }
        });
        this.evalResult.rows = res.data;
      });
    },
    /**
     * @函数功能:审计状态在信息补全和审计确认的时候 去校验审计结果和现状描述 如果审计结果是(待审计的)一定要选择成其他的审计结果 如果是不合适的，一定要填写现状描述
     * @参数输入:
     * @函数返回:
     */
    cellClassName({ row, column, rowIndex, columnIndex }) {
      if (!column) {
        return;
      }
      if (this.progressData.status === "12" || this.progressData.status === "13") {
        //信息补充阶段和审计结果阶段 现状描述（除了审计结果是不适用的情况下）都是必填项
        if (column.property === "remark" && row.status !== "-1" && !row.remark) {
          return "required";
        }
      }
      //审计结果阶段不能有待审计选择
      if (this.progressData.status === "13") {
        if (column.property === "status" && row.status === "100") {
          return "required";
        }
      }
      //不适用的置灰颜色值
      if (row.status === "-1") {
        return "disabledStyle";
      }
    },
    addHiveTable() {
      this.dbTableDetailVal = ["1"];
      let obj = {
        tableName: "",
        dbName: "",
        assetId: this.query.assetId,
        domain: this.contentData.domain,
        reportId: this.contentData.id,
      };
      this.evalSettingTable.rows.push(obj);
    },
    /**
     * @函数功能:保存审计项设定
     * @参数输入:
     * @函数返回:
     */
    saveHiveTable() {
      let evalSettingRows = this.evalSettingTable.rows;
      let sign = false;
      evalSettingRows.forEach((item) => {
        if (!item.dbName || !item.tableName) {
          sign = true;
        }
      });
      if (sign) {
        this.message.warning({ message: "有库名或者表名未填写" });
        return;
      }
      let loading = this.openLoading();
      savehiveApi(this.evalSettingTable.rows).then((res) => {
        loading.close();
        this.message.success({ message: res.msg });
      });
    },
    /**
     * @函数功能:界面最下面的保存按钮
     * @参数输入:refresh:Boolean 是否刷新审计结果列表
     * @函数返回:
     */
    save(refresh) {
      this.saveOrSubmit("save", refresh);
    },
    saveOrSubmit(opera, refresh) {
      if (opera === "submit") {
        var loading = this.openLoading();
      }
      saveOrSubmitApi({
        reportId: this.query.id,
        status: this.progressData.status,
        opera: opera, //save 保存 submit提交
        items: this.evalResult.rows,
      }).then((res) => {
        if (opera === "submit") {
          loading.close();
          this.initPage();
        } else if (opera === "save") {
          refresh && this.getReportItems();
          refresh && this.message.success({ message: res.msg }); //现状描述失去焦点的时候保存但是不需要提示
        }
      });
    },
    saveAndSubmit() {
      let sign = false;
      let rows = this.evalResult.rows;
      //在信息补全和审计确认的状态下 风险结果不能是待审计 如果审计结果是不符合，现状描述一定要填写
      rows.forEach((item) => {
        if (this.progressData.status === "12" || this.progressData.status === "13") {
          if (item.status !== "-1" && !item.remark) {
            sign = true;
          }
        } else if (this.progressData.status === "13") {
          if (item.status === "100") {
            sign = true;
          }
        }
      });
      if (sign) {
        this.message.warning({
          message: "有必填项未填写",
        });
        return;
      }
      this.saveOrSubmit("submit");
    },
    questionnaireClick() {
      this.$router.push({
        path: "/question",
        query: {
          reportId: this.query.id,
        },
      });
    },
    //误报
    errReportConfirm() {
      riskMisreportApi({ ids: [this.selectRisk.id], status: "121", remark: this.ruleForm.remark }).then((res) => {
        if (res.code == 0) {
          this.errDiaShow = false;
          this.message.success({ message: res.msg });
          this.getRiskList();
          this.getReportItems(); //审计结果
          this.getReportDetail(); //审计进度数据获取
          return;
        }
        this.message.warning({ message: res.msg });
      });
    },
    /**
     * @函数功能:同步漏洞平台 这个点击是同步所有的漏洞平台
     * @参数输入:
     * @函数返回:
     */
    setRiskSoc() {
      // this.holeDiaShow = true;
      this.utils.$confirm({ content: "是否确认同步漏洞并生成审计报告？" }, () => {
        this.selectRisk = {};
        this.asyncHoleConfirm();
      });
    },
    /**
     * @函数功能:同步漏洞平台 弹框的确认按钮
     * @参数输入:relationId:"" 是同步所有的漏洞平台并生成报告  riskIds:[] 这个是同步一个到漏洞平台
     * @函数返回:
     */
    asyncHoleConfirm() {
      let riskIds = this.selectRisk.id ? [this.selectRisk.id] : [];
      let relationId = this.selectRisk.id ? "" : this.query.id;
      riskSocApi({ relationId: relationId, riskIds: riskIds, dateType: "datasec_report" }).then((res) => {
        // this.holeDiaShow = false;
        this.message.success({ message: res.msg });
        this.getRiskList();
        this.getReportDetail(); //审计进度数据获取
      });
    },
  },
  watch: {},
  destroyed() {
    window.clearInterval(this.timer);
  },
};
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
.base-info {
  line-height: 30px;
}
.btn-box {
  margin-bottom: 10px;
}
::v-deep .required.el-table__cell .el-input input {
  border-color: red;
}
::v-deep .required.el-table__cell .el-textarea textarea {
  border-color: red;
}
::v-deep .disabledStyle.el-table__cell {
  background: #e6e6e6;
}
</style>
